package com.shenhaofeng.app.adapter;

import android.support.annotation.CallSuper;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;


/**
 * Created by Administrator on 2016/7/22.
 */
public abstract class SingleTypeMoreAdapter<VH extends RecyclerView.ViewHolder, T> extends MoreAdapter {


    public static final int SINGE_TYPE = Module.NO_TYPE;


    private Module<T> mModule = Module.createModule(SINGE_TYPE);


    public SingleTypeMoreAdapter() {
        super.addModule(mModule);
    }



    @Override
    public final RecyclerView.ViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
        return onCreateSingleViewHolder(parent, viewType);
    }


    @CallSuper
    @Override
    protected void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        onBindSingleItemViewHolder((VH) holder, position);
    }


    /**
     * 绑定数据到item
     *
     * @param holder
     * @param position
     */
    protected abstract void onBindSingleItemViewHolder(VH holder, int position);


    protected abstract VH onCreateSingleViewHolder(ViewGroup parent, int viewType);




    @Override
    public void clearAllItem() {
        throw new UnsupportedOperationException("禁止移除所有Module,如果需要清除item数据请调用clearAllContentItem()");
    }


    /**
     * 清除所有内容
     */
    public void clearAllContentItem(){
        getModule().clear();
    }


    /**
     * 获取内容的Module
     *
     * @return
     */
    public Module<T> getModule() {
        return mModule;
    }


    /**
     * 单类型Module中禁止使用该方法添加新的Module
     *
     * @param module
     */
    @Deprecated
    @Override
    public void addModule(Module module) {
        throw new UnsupportedOperationException("请使用setModule");
    }


}
